package leetcode.p114;

public class Foo2 {
    private int step = -1;
    public Foo2(){

    }

    public void first(Runnable printFirst) throws InterruptedException {
        synchronized (this){
            while (step != 1){
                this.wait();
            }
        }
        printFirst.run();
    }

    public void second(Runnable printSecond) throws InterruptedException {
        synchronized (this){
            while (step != 2){
                this.wait();
            }
        }
        printSecond.run();
    }

    public void third(Runnable printThird) throws InterruptedException {
        synchronized (this){
            while (step != 3){
                this.wait();
            }
        }
        printThird.run();
    }
}
